from typing import List


class Solution:
    def findAnagrams(self, s: str, p: str) -> List[int]:
        countP = [0] * 26
        for ch in p:
            countP[ord(ch) - ord('a')] += 1

        ans, left, right = [], 0, 0
        while right < len(s):
            c = ord(s[right]) - ord('a')
            if countP[c] > 0:
                countP[c] -= 1
            else:
                while countP[c] <= 0:
                    countP[ord(s[left]) - ord('a')] += 1
                    left += 1
                countP[c] -=1

            if right - left + 1 == len(p):
                ans.append(left)
            right += 1
        return ans
        
